package com.kepler.social.web.controller;

import com.kepler.social.app.port.UserRegisterPort;
import com.kepler.social.common.constants.BusinessState;
import com.kepler.social.common.constants.TipsConst;
import com.kepler.social.web.common.HttpResult;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/register")
@Slf4j
public class RegisterController {

    @Resource
    private UserRegisterPort userRegisterPort;

    // TODO verif -> verification
    @RequestMapping(value = "/verif-mail/send")
    public HttpResult verifMailSend(String email) {
        userRegisterPort.sendVerifMail(email);
        return HttpResult.success(TipsConst.email_send);
    }

    @RequestMapping(value = "/verif-mail/verify")
    public String verifMailVerify(String token) {
        userRegisterPort.verifyVerifMail(token);
        return  TipsConst.email_success_verified;
    }

    /**
     * 手机验证码
     *
     * @param mobilePhoneNumber
     * @return
     */
    @RequestMapping(value = "/sms-captcha/send")
    public HttpResult smsCaptchaSend(Integer countryCallingCode, Long mobilePhoneNumber) {
        userRegisterPort.sendMobilePhoneRegisterCaptcha(countryCallingCode, mobilePhoneNumber);
        return new HttpResult(BusinessState.OK.code, TipsConst.mobile_phone_captcha_sent);
    }

    @RequestMapping(value = "/mobile_phone")
    public HttpResult verifMobilePhoneVerify(Integer countryCallingCode, Long mobilePhoneNumber, Integer captcha) {
        userRegisterPort.verifyMobilePhoneRegisterCaptcha(countryCallingCode, mobilePhoneNumber, captcha);
        return new HttpResult(BusinessState.OK.code, TipsConst.success_register);
    }

}
